//
//  UserShoesCell.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/31.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "UserShoesCell.h"
#import "UserEquipModel.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSDate+FormateString.h"
#import "NSDate+CM_DateTools.h"
#import "UIImageView+CM_ShowImage.h"


@interface UserShoesCell ()
@property (weak, nonatomic) IBOutlet UIView *userShoesView;
@property (weak, nonatomic) IBOutlet UIImageView *userShoesImageView;
@property (weak, nonatomic) IBOutlet UILabel *userShoesBrand;
@property (weak, nonatomic) IBOutlet UILabel *userShoeBuyDayLabel;
@property (weak, nonatomic) IBOutlet UILabel *userShoeSETLabel;

@end

@implementation UserShoesCell
- (void)setViewModle:(UserEquipModel *)viewModle {
    
    _viewModle = viewModle;

    [self.userShoesImageView sd_setImageWithURL:[NSURL URLWithString:viewModle.ShoesUrl] placeholderImage:[UIImage imageNamed:@"球鞋-未设置"] options:SDWebImageLowPriority |SDWebImageRetryFailed];
    
    if (viewModle.ShoesBuyTime.length <= 0 && viewModle.ShoesName.length <= 0) {
        self.userShoeSETLabel.hidden = NO;
        self.userShoesBrand.hidden = YES;
        self.userShoeBuyDayLabel.hidden = YES;
    }else {
        self.userShoeSETLabel.hidden = YES;
        self.userShoesBrand.hidden = NO;
        self.userShoeBuyDayLabel.hidden = NO;
        self.userShoeBuyDayLabel.text = [self disposeShoesBuyTimeWith:viewModle.ShoesBuyTime];
        self.userShoesBrand.text = viewModle.ShoesName;
    }
}

- (NSString *)disposeShoesBuyTimeWith:(NSString *)buyTime {
    
    BOOL ischinese = [NSBundle currentLanguageIsChinese];
    if (buyTime.length > 0) {
        NSDate *formDate = [NSDate formateYearMonthString:buyTime];
        NSDate *toDate = [NSDate formateYearMonthString:[[NSDate date] formateYearAndMonth]];
        if (formDate) {
            NSInteger months = [NSDate numberOfMonthsWithFromDate:formDate toDate:toDate];
            
            if (months < 12) {
                months = (months <= 0 ? 1:months);
                return ischinese ? [NSString stringWithFormat:@"鞋龄: %zd 个月",months] : [NSString stringWithFormat:@"Age: %zd months",months];
            }else {
                months = (months <= 0 ? 1:months);
                NSInteger years = months / 12;
                return ischinese ? [NSString stringWithFormat:@"鞋龄: %zd 年以上",years] :[NSString stringWithFormat:@"Age: More than %zd years",years];
            }
            
        }else{
            return @"";//鞋龄":@"Age:
        }
    }
     return  @"";
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.userShoesView.layer.borderWidth = 1.5;
    self.userShoesImageView.layer.borderWidth = 1.5;
    self.userShoesView.layer.borderColor = [UIColor colorWithHex:0x83f09f].CGColor;
    self.userShoesImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.userShoesView.layer.cornerRadius =  self.userShoesView.bounds.size.width * 0.5;
    self.userShoesImageView.layer.cornerRadius =  self.userShoesImageView.bounds.size.width * 0.5;
    self.userShoesView.layer.masksToBounds = YES;
    self.userShoesImageView.layer.masksToBounds = YES;
     self.userShoesImageView.userInteractionEnabled = YES;
    [self.userShoesImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(setHeadIcon)]];
    
    self.userShoeSETLabel.text = NSLocalizedString(@"User.Not Set", @"未设置");
}
- (void)setHeadIcon {
    [self.userShoesImageView showImage];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
